//
//  RepairerManageViewController.m
//  Manage
//
//  Created by 杨康 on 2017/11/23.
//  Copyright © 2017年 杨康. All rights reserved.
//

#import "RepairerManageViewController.h"
#import "AddRepairerViewController.h"
#import "EditRepairerViewController.h"
@interface RepairerManageViewController ()
@property(nonatomic,strong)ykTableView *tableView;
@end

@implementation RepairerManageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"修理商管理";
    UIButton *leftButton=(UIButton *)self.navigationItem.leftBarButtonItem.customView;
    leftButton.selected=YES;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
                                                                                           target:self
                                                                                           action:@selector(addAction)];
    self.navigationItem.rightBarButtonItem.tintColor=[UIColor whiteColor];
    
    
    
    UISearchBar *searchBar=[[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 44)];
    
    
    searchBar.placeholder=@"搜索修理商";
    searchBar.backgroundImage=[NetworkPath createImageWithColor:[UIColor colorF]];
    
    [[UISearchBar appearance] setSearchFieldBackgroundImage:[self searchFieldBackgroundImage] forState:UIControlStateNormal];
    UITextField *txfSearchField = [searchBar valueForKey:@"_searchField"];
    [txfSearchField setDefaultTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13.5]}];
    
    searchBar.searchTextPositionAdjustment = UIOffsetMake(7, 0);
    
    
    
    
    
    self.tableView=[SingLeton myTableViewWithFrame:CGRectMake(0, TOP_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT-TOP_HEIGHT) withRefresh:NO didSelect:^(ykTableView *tableView, NSIndexPath *indexPath) {
        EditRepairerViewController *vc=[[EditRepairerViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }];
    [self.view addSubview:self.tableView];
    self.tableView.tableHeaderView=searchBar;
    
    
    
    
    self.tableView.className=@"RepairerCell";
    NSMutableArray *itemArr=[NSMutableArray array];
    
    
    for (int i=0; i<5; i++) {
        repairerData *dataObj=[[repairerData alloc]init];
        dataObj.image=@"";
        dataObj.text=@"修理商名称";
        dataObj.address=@"我家在东北松花江上啊我家在东北松花江上啊";
        [itemArr addObject:dataObj];
        
        
        
    }
    [self.tableView.dataArray addObject:itemArr];
    [self.tableView reloadData];
}

//调用方法
- (UIImage*)searchFieldBackgroundImage {
    UIColor*color = [UIColor whiteColor];
    CGFloat cornerRadius = 5;
    CGRect rect =CGRectMake(0,0,28,28);
    
    UIBezierPath*roundedRect = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:cornerRadius];
    roundedRect.lineWidth=0;
    
    UIGraphicsBeginImageContextWithOptions(rect.size,NO,0.0f);
    [color setFill];
    [roundedRect fill];
    [roundedRect stroke];
    [roundedRect addClip];
    
    UIImage *image =UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}
-(void)addAction
{
    AddRepairerViewController *vc=[[AddRepairerViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

@end
